package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.KingBdCangw;
import com.ruoyi.system.service.IKingBdCangwService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓位Controller
 * 
 * @author ruoyi
 * @date 2021-04-26
 */
@RestController
@RequestMapping("/system/cangw")
public class KingBdCangwController extends BaseController
{
    @Autowired
    private IKingBdCangwService kingBdCangwService;

    /**
     * 查询仓位列表
     */
    @PreAuthorize("@ss.hasPermi('system:cangw:list')")
    @GetMapping("/list")
    public TableDataInfo list(KingBdCangw kingBdCangw)
    {
        startPage();
        List<KingBdCangw> list = kingBdCangwService.selectKingBdCangwList(kingBdCangw);
        return getDataTable(list);
    }

    /**
     * 导出仓位列表
     */
    @PreAuthorize("@ss.hasPermi('system:cangw:export')")
    @Log(title = "仓位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(KingBdCangw kingBdCangw)
    {
        List<KingBdCangw> list = kingBdCangwService.selectKingBdCangwList(kingBdCangw);
        ExcelUtil<KingBdCangw> util = new ExcelUtil<KingBdCangw>(KingBdCangw.class);
        return util.exportExcel(list, "cangw");
    }

    /**
     * 获取仓位详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cangw:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(kingBdCangwService.selectKingBdCangwById(id));
    }

    /**
     * 新增仓位
     */
    @PreAuthorize("@ss.hasPermi('system:cangw:add')")
    @Log(title = "仓位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KingBdCangw kingBdCangw)
    {
        return toAjax(kingBdCangwService.insertKingBdCangw(kingBdCangw));
    }

    /**
     * 修改仓位
     */
    @PreAuthorize("@ss.hasPermi('system:cangw:edit')")
    @Log(title = "仓位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KingBdCangw kingBdCangw)
    {
        return toAjax(kingBdCangwService.updateKingBdCangw(kingBdCangw));
    }

    /**
     * 删除仓位
     */
    @PreAuthorize("@ss.hasPermi('system:cangw:remove')")
    @Log(title = "仓位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(kingBdCangwService.deleteKingBdCangwByIds(ids));
    }
}
